<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-${model.modelL}-add">
#foreach($field in $fieldList)
#if($field.isPk != "Y"&&${field.inputType}!="none")
#if(${field.inputType}=="date")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8">
			    <div class="input-group"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
			       <input type="text" id="${field.field}" name="${field.field}" class="form-control" value="" placeholder="yyyy-MM-dd"/>
			    </div>
			</div>
		</div>
#elseif(${field.inputType}=="time")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8">
			    <div class="input-group"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
			       <input type="text" id="${field.field}" name="${field.field}" class="form-control" value="" placeholder="HH:mm:ss"/>
			    </div>
			</div>
		</div>
#elseif(${field.inputType}=="datetime")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8">
			    <div class="input-group"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
			       <input type="text" id="${field.field}" name="${field.field}" class="form-control" value="" placeholder="yyyy-MM-dd HH:mm:ss"/>
			    </div>
			</div>
		</div>
#elseif(${field.inputType}=="htmleditor")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8">
		       <input id="${field.field}" name="${field.field}" type="hidden">
			   <div class="summernote" id="${field.field}_summernote"></div>
			</div>
		</div>
#elseif(${field.inputType}=="textarea")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8">
				<textarea rows="6" cols=""  id="${field.field}" name="${field.field}" th:inline="text" class="form-control"></textarea>
			</div>
		</div>
#elseif(${field.inputType}=="select"&&${field.inputValueOne} == "sys_dept")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8"> 
		       <input name="${field.field}"  type="hidden" id="treeId"/>
		       <input type="text" id="treeName" name="treeName" class="form-control" onclick="selectDeptTree()" readonly="true"/>
		    </div>
		</div> 
#elseif(${field.inputType}=="file")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8"> 
				<div>
					<img src="/img/profile.png"  id="${field.field}_image" height="60" width="60"/>
				</div>
		         <div style="width: 80%;float: left;">   
					<input id="${field.field}_uploadfile" name="avatarfile" multiple type="file"> 
					<input type="hidden" name="${field.field}" id="${field.field}"/>
				</div>
				<button type="button" class="btn btn-primary" onclick="javascript:${field.field}_fileUpload()" style="float: right;">上传</button>
		    </div>
		</div> 
#elseif(${field.inputType}=="radio")
#if(${field.inputValue} == "")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8"> 
		      <div class="onoffswitch">
                         <input type="hidden" class="onoffswitch-checkbox" name="${field.field}" id="${field.field}"/>
                         <input type="checkbox" th:checked="true" class="onoffswitch-checkbox" name="${field.field}_radio"/>
                         <label class="onoffswitch-label" for="${field.field}">
                             <span class="onoffswitch-inner"></span>
                             <span class="onoffswitch-switch"></span>
                         </label>
              </div>
            </div>
		</div>
#else
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
		    <div class="col-sm-8">
			    <div class="radio-box" th:each="dict : ${@dict.selectDictData('${field.inputValue}')}">
					<input type="radio" th:id="${dict.dictCode}" name="${field.field}" th:value="${dict.dictValue}" th:checked="${ dict.isDefault == 'Y' ? true : false}">
					<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
				</div>
			</div>
		</div>
#end 
#elseif(${field.inputType}=="select")
#if(${field.inputValueTwo} == "")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8"> 
		      <select id="${field.field}" name="${field.field}" class="form-control m-b" th:with="type=${@dict.selectDictData('${field.inputValue}')}">
                  <option value="">请选择</option>
                   <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
               </select>
            </div>
		</div> 
#elseif(${field.inputValueTwo} != "")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8"> 
		      <select id="${field.field}" name="${field.field}" class="form-control m-b" th:with="type=${ @${field.inputValueOneU}ServiceImpl.selectAll()}">
                  <option value="">请选择</option>
                   <option th:each="dict : ${type}" th:text="${ dict.${field.inputValueTwoL}}" th:value="${dict.id}"></option>
               </select>
            </div>
		</div> 
#end
#elseif(${field.inputType}=="checkbox")
#if(${field.inputValueTwo} == "")
		<div class="form-group">
			<label class="col-sm-3 control-label">${field.comment}：</label>
			<input name="${field.field}" id="${field.field}"  type="hidden" />
			<div class="col-sm-8">
				<label th:each="role:${@dict.selectDictData('${field.inputValue}')}" class="check-box">
					<input name="${field.field}s" id="${field.field}s" type="checkbox" th:value="${role.dictValue}" th:text="${role.dictLabel}">
				</label>  
			</div>
		</div>
#elseif(${field.inputValueTwo} != "")
		<div class="form-group">
			<label class="col-sm-3 control-label">${field.comment}：</label>
			<input name="${field.field}" id="${field.field}"  type="hidden" />
			<div class="col-sm-8"> 
				<select id="${field.field}s" name="${field.field}s" class="form-control select2-hidden-accessible" multiple="">
					<option th:each="${ @${field.inputValueOneU}ServiceImpl.selectAll()}" th:text="${ dict.${field.inputValueTwoL}}" th:value="${dict.id}"></option>
				</select>
			</div>
		</div>
#end 
#else
        <div class="form-group">	
            <label class="col-sm-3 control-label">${field.comment}：</label>
            <div class="col-sm-8">
                <input id="${field.field}" name="${field.field}" class="form-control" type="text" placeholder="请输入${field.comment}"/>
            </div>
        </div>
#end 
#end
#end
 
    </form>
    </div>

    <div th:include="include::footer"></div>
    
<script type="text/javascript" th:inline="javascript">

var prefix = ctx + "${model.modulePackage}/${model.modelL}"

	layui.use('laydate', function(){
	  var laydate = layui.laydate;
#foreach($field in $fieldList)
#if(${field.inputType}=="datetime")
  //日期时间选择器
	  laydate.render({
	    elem: '#${field.field}'
	    ,type: 'datetime'
	  });
#elseif(${field.inputType}=="date")
	  laydate.render({
	    elem: '#${field.field}'
	  });
#elseif(${field.inputType}=="time")
	  laydate.render({
	    elem: '#${field.field}'
	    ,type: 'time'
	  });
#end
#end	  
	});


#foreach($field in $fieldList)
#if(${field.inputType}=="htmleditor")
    $('.summernote').summernote({
		height : '220px',
		lang : 'zh-CN'
	});
#end
#end 


$("#form-${model.modelL}-add").validate({
	rules:{
#foreach($field in $fieldList)
#if($field.isPk != "Y")
#if(!$field.nullable)
		${field.field}:{
			required:true
		},
#elseif($field.validate=="email")
		${field.field}:{
			required:true,
			 email:true
		},
#elseif($field.validate=="mobile")
		${field.field}:{
			required:true,
			isPhone:true
		},
#elseif($field.validate=="number")
		${field.field}:{
			required:true,
			number:true
		},
#elseif($field.validate=="date")
		${field.field}:{
			required:true,
			dateISO:true
		},
#elseif($field.validate=="integer")
		${field.field}:{
			required:true,
			digits:true
		},
#elseif($field.validate=="url")
		${field.field}:{
			required:true,
			url:true
		},
#end
#end
#end
	}
});

	function submitHandler() {
		if ($.validate.form()) {
#foreach($field in $fieldList)
#if(${field.inputType}=="htmleditor")
			var sHTML = $('#${field.field}_summernote').code();
			$("#${field.field}").val(sHTML);
#end
#if(${field.inputType}=="radio")
			var ${field.field}_radio = $("input[name='${field.field}_radio']").is(':checked') == true ? 0 : 1;
			$("#${field.field}").val(${field.field}_radio);
#end
#if(${field.inputType}=="checkbox")
#if(${field.inputValueTwo} == "")
			$("#${field.field}").val($.form.selectCheckeds("${field.field}s"));	
#elseif(${field.inputValueTwo} != "")
			$("#${field.field}").val($.form.selectSelects("${field.field}s"));
#end
#end 
#end
			$.operate.save(prefix + "/add", $('#form-${model.modelL}-add').serialize());
		}
	}
#foreach($field in $fieldList)
#if(${field.inputValueOne} == "sys_dept")
	/*用户管理-新增-选择部门树*/
	function selectDeptTree() {
       	var treeId = $("#treeId").val();
       	var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
       	var url = ctx + "system/dept/selectDeptTree/" + deptId;
		var options = {
			title: '选择部门',
			width: "380",
			url: ctx + "system/dept/selectDeptTree/" + deptId,
			callBack: doSubmit
		};
		$.modal.openOptions(options);
	}
	function doSubmit(index, layero){
		var tree = layero.find("iframe")[0].contentWindow.$._tree;
		if ($.tree.notAllowParents(tree)) {
			var body = layer.getChildFrame('body', index);
   			$("#treeId").val(body.find('#treeId').val());
   			$("#treeName").val(body.find('#treeName').val());
   			layer.close(index);
		}
	}
#elseif(${field.inputType}=="file")
	$(document).ready(function(){
	 
		${field.field}_fileinputlist();
	});

/** 初始化文件框*/
	function ${field.field}_fileinputlist(){
		$('#${field.field}_uploadfile').fileinput({
			language: 'zh', //设置语言
			showPreview: false,//是否显示预览,不写默认为true
			showUpload: false, //是否显示上传按钮,跟随文本框的那个
			showRemove : true, //显示移除按钮,跟随文本框的那个
			showCaption: true,//是否显示标题,就是那个文本框
			uploadAsync : false, //默认异步上传
			elErrorContainer: '#upload-file-errors',
			maxFileCount: 1, //表示允许同时上传的最大文件个数
			maxFileSize: 102400,      //单位为kb，如果为0表示不限制文件大小
			enctype: 'multipart/form-data',
			dropZoneTitle: '拖拽文件到这里 &hellip;<br>仅仅支持单个文件同时上传',//重新定义提示
			msgFilesTooMany: '选择上传的文件数量({n}) 超过允许的最大数值{m}！',
	//        allowedFileExtensions: ["xls", "xlsx"],
			uploadUrl: ctx + "file/uploadImg",
		});
	}

	/*图片上传*/
	function ${field.field}_fileUpload() {
		//文件默认上传方法,传ID:uploadfile
		$('#${field.field}_uploadfile').fileinput("upload");
		//同步上传错误处理
		$('#${field.field}_uploadfile').on('filebatchuploaderror', function(event, data, msg) {
			// get message
			$.modal.alertError(msg);
			//重置
			$('#${field.field}_uploadfile').fileinput("clear");
			$('#${field.field}_uploadfile').fileinput("reset");
			$('#${field.field}_uploadfile').fileinput('refresh');
			$('#${field.field}_uploadfile').fileinput('enable');
		});
		//同步上传后从后台返回结果
		$('#${field.field}_uploadfile').on('filebatchuploadsuccess', function(event, data, previewId, index) {
			var result = data.response;
			if (result.code == 0) {
				 
				$.modal.alertSuccess(result.msg);
				$('#${field.field}').val(result.avatar);
				$('#${field.field}_image').attr("src","/profile/"+result.avatar);   
			} else {
				$.modal.alertError(result.msg);
				//重置
				$('#${field.field}_uploadfile').fileinput("clear");
				$('#${field.field}_uploadfile').fileinput("reset");
				$('#${field.field}_uploadfile').fileinput('refresh');
				$('#${field.field}_uploadfile').fileinput('enable');
			}
		});

	}
#end
#end

</script> 
 
</body>
</html>
